import {
  createDemocracyEvaluation,
  getSectionChiefStaff,
  checkDemocracyEvaluationTime,
  getTeamPlayerList,
  getCategoryList,
  getContentList,
  getCategoryGet,
  login,
  getAppSetDetail
} from '../services/api';
import { message } from 'antd';

const SettingModel = {
  namespace: 'Public',
  state: {
    setTing: {},
    tabList: []
  },
  effects: {
    *createDemocracyEvaluation({ payload }, { call, put }) {
      const response = yield call(createDemocracyEvaluation, { form: payload.form, cadre: payload.cadre, staff: payload.staff });
      return response
    },
    *getSectionChiefStaff({ payload }, { call, put }) {
      const response = yield call(getSectionChiefStaff, { deptIds: payload.deptIds, generalStaff: payload.generalStaff });
      return response
    },
    *checkDemocracyEvaluationTime({ payload }, { call, put }) {
      const response = yield call(checkDemocracyEvaluationTime);
      return response
    },
    //获取配置信息接口
    *getAppSetDetail({ payload }, { call, put }) {
      const response = yield call(getAppSetDetail);
      return response
    },
    //获取关于我们的团队成员列表接口
    *getTeamPlayerList({ payload }, { call, put }) {
      const response = yield call(getTeamPlayerList);
      return response
    },
    //获取tab接口
    *getCategoryList({ payload }, { call, put }) {
      const response = yield call(getCategoryList);
      const data = response?.data?.rows?.map(i => {
        return {
          ...i,
          name: i.categoryTitle,
        }
      }) || []
      yield put({
        type: 'saveTab',
        payload: { tabList: data }
      })
      return response
    },
    //获取tab下的list
    *getContentList({ payload }, { call, put }) {
      const response = yield call(getContentList, { categoryId: payload.categoryId, pageSize: payload.pageSize });
      return response
    },
    //获取详情接口
    *getCategoryGet({ payload }, { call, put }) {
      const response = yield call(getCategoryGet, { id: payload.id });
      return response
    },
    *login({ payload }, { call, put }) {
      const response = yield call(login, { account: payload.account, password: payload.account });
      return response
    },
    *getAppSetDetail({ payload }, { call, put }) {
      const response = yield call(getAppSetDetail);
      yield put({
        type: 'saveCurrentView',
        payload: { setTing: response.data }
      })
      return response
    },
  },
  reducers: {
    saveCurrentView(state, { payload }) {
      return { ...state, setTing: payload.setTing };
    },
    saveTab(state, { payload }) {
      return { ...state, tabList: payload.tabList };
    },
  },
};
export default SettingModel;
